import get_global from '@dfeidao/atom-web/global/get';
import get from '@dfeidao/atom-web/local/get';
// 重新渲染树形图
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import hide from '@dfeidao/atom-web/ui/hide';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// 修改
	const _id = get(fd, '_id');
	const productid = get_global('productid');
	const name = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="name"]').value;
	const old_name = get(fd, 'name') as string;
	if (!name) {
		error("请完善权限组名称");
		return;
	} else {
		if (old_name === name) {
			success("修改成功");
			fire('zj-000001', 'ec-001');
			hide(fd.data.node);
			fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="name"]').value = '';
			return;
		} else {
			const upd_res = await nodejs('functional-permissions/zj-000004/s001', {
				_id,
				name,
				productid
			});
			if (upd_res === 'other') {
				error("权限组名称重复");
				return;
			}
			if (upd_res === 'success') {
				success("修改成功");
				fire('zj-000001', 'ec-001');
			} else {
				error("修改失败");
			}
			hide(fd.data.node);
			fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="name"]').value = '';
		}

	}
}
